#include <memory>
#include <cassert>
#include <iostream>
using namespace std;
using namespace std::tr1;

class A{};

int main()
{
    weak_ptr<A> w;
    assert(w.expired());
    {
        shared_ptr<A> p(new A());
        assert(p.use_count()==1);
        w=p;
        assert(p.use_count()==w.use_count());
        assert(p.use_count()==1);

        // Create a shared_ptr from the weak_ptr
        shared_ptr<A> p2(w);
        assert(p2==p);
    }
    assert(w.expired());
    shared_ptr<A> p3=w.lock();
    assert(!p3);
}
